<template>
  <Layout>
    <div style="min-height: 600px">
      <el-card shadow="never" style="min-height: 400px" v-if="blog.id">
        <div slot="header">
          <span>{{ blog.title }}</span>
          <el-button
            @click="$router.go(-1)"
            style="float: right; padding: 3px 0"
            type="text"
            icon="el-icon-d-arrow-left"
            >返回</el-button
          >
        </div>
        <div style="font-size: 0.9rem; line-height: 1.5; color: #606c71">
          发布 {{ blog.created_at }} <br />
          更新 {{ blog.updated_at }}
        </div>
        <div
          style="
            font-size: 1.1rem;
            line-height: 1.5;
            color: #303133;
            border-bottom: 1px solid #e4e7ed;
            padding: 5px 0px 5px 0px;
          "
        >
          <!-- <pre style="font-family: '微软雅黑'">{{ blog.description }}</pre> -->
        </div>
        <div
         v-html="mdToHtml(blog.content)"
          class="markdown-body"
          style="padding-top: 20px"
        ></div>
        <p>
          <span
            v-for="tag in blog.tags"
            :key="tag.id">
            {{ tag.title }}
          </span>
        </p>
      </el-card>
      <el-card
        shadow="never"
        style="
          margin-bottom: 20px;
          padding: 20px 0px 20px 0px;
          text-align: center;
        "
        v-if="!blog.id"
      >
        <font style="font-size: 30px; color: #dddddd">
          <b>没有更新 ╮(๑•́ ₃•̀๑)╭</b>
        </font>
      </el-card>
    </div>
  </Layout>
</template>

<page-query>
query ($id: ID!){
  post: strapiPost (id: $id) {
    id
    title
    content
    user
    tags {
      id
      title
    }
    created_at
    updated_at
  }
}
</page-query>


<script>
import MarkdownIt from 'markdown-it'
const md = new MarkdownIt()

export default {
  name: 'PostPage',
  methods: {
    mdToHtml (markdown) {
      return md.render(markdown)
    }
  },
  data() {
    return {
      blog: {
        id: '',
        title: '',
        content: '',
        user: '',
        tags: {
          id: '',
          title: ''
        },
        created_at: '',
        updated_at: ''
      }
    }
  },
  mounted() {
    this.blog = this.$page.post
  }
}
</script>

<style>

</style>